package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
@Slf4j
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 护理项目分页条件查询
     * @return
     */
    @GetMapping
    @ApiOperation("护理项目分页条件查询")
    public ResponseResult< PageResponse<NursingProjectVo>> getByPage (String name,
                                    @RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                     Integer status) {
        PageResponse<NursingProjectVo> page =  nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(page);
    }

    /**
     * 添加护理项目
     * @return
     */
    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 编辑更新护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("编辑更新护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理项目")
    public ResponseResult enableDisable (@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用护理项目，id:{},status:{}",id,status);
        nursingProjectService.enableDisable(id, status);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteBuId(@PathVariable Long id){
        nursingProjectService.deleteBuId(id);
        return ResponseResult.success();
    }

    /**
     *查询所有护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> all() {
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.all();
        return ResponseResult.success(nursingProjectVo);
    }
}